package cn.itcast

/*
date:2022.03.16
author:dong hui
 */

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object WordCount_Online {
  def main(args: Array[String]): Unit = {
    val sparkconf = new SparkConf().setAppName("WordCount_Online")
    val sc = new SparkContext(sparkconf)
    val data : RDD[String] = sc.textFile(args(0))
    val words :RDD[String] = data.flatMap(_.split(" "))
    val wordAndOne :RDD[(String, Int)] = words.map(x =>(x,1))
    val result: RDD[(String, Int)] = wordAndOne.reduceByKey(_+_)
    result.saveAsTextFile(args(1))
    sc.stop()
  }
}
